import type { CreatePlottingSceneDTO } from './dto';

import { requestClient } from '#/api/request';

export namespace PlottingSceneApi {
  export const createPlottingScene = (dto: CreatePlottingSceneDTO) => {
    const formData = new FormData();
    formData.append('name', dto.name);
    formData.append('smlString', dto.smlString);
    formData.append('createdUser', dto.userId);
    formData.append('thumbnail', dto.thumbnail);
    return requestClient.post(
      `dsc-systemMS/dsc-plotting-scene/create`,
      formData,
      {
        headers: {
          'Content-Type': 'multipart/form-data',
        },
      },
    );
  };

  export const getPlottingSceneList = (
    userId: string,
    pageSize: number,
    currentPage: number,
    keyword: string,
  ) => {
    return requestClient.get('dsc-systemMS/dsc-plotting-scene/list', {
      params: {
        userId,
        pageSize,
        pageIndex: currentPage,
        keyword,
      },
    });
  };

  export const deletePlottingScene = (userId: string, sceneId: string) => {
    return requestClient.delete('dsc-systemMS/dsc-plotting-scene/delete', {
      params: {
        userId,
        sceneId,
      },
    });
  };

  export const updatePlottingScene = (
    sceneId: string,
    dto: CreatePlottingSceneDTO,
  ) => {
    const formData = new FormData();
    formData.append('name', dto.name);
    formData.append('smlString', dto.smlString);
    formData.append('createdUser', dto.userId);
    formData.append('thumbnail', dto.thumbnail);
    return requestClient.put(
      `dsc-systemMS/dsc-plotting-scene/update?sceneId=${sceneId}`,
      formData,
      {
        headers: {
          'Content-Type': 'multipart/form-data',
        },
      },
    );
  };
}
